﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
//using SimpleMapTemplate;
using SimpleQuartzTemplate.Services;

namespace SimpleQuartzTemplate.Controllers
{
	[Route("api/[controller]")]
	[ApiController]
	public class UserController : ControllerBase
	{
		IUserService userService;
		public UserController(IUserService userService)
		{
			this.userService = userService;
		}
		[HttpGet("user")]
		public async Task<IActionResult> User()
		{
			UserEntity user = new UserEntity();

			var type = typeof(UserEntity);// DtoWrapper.CreateAnonymousType(user);
			return Ok(Activator.CreateInstance(type));
		}

		[HttpGet("user1")]
		public async Task<IActionResult> User1()
		{
			UserEntity user = new UserEntity();
			return Ok(user);
		}
		[HttpPost("code")]
		public IActionResult GetCaptcha()
		{
			string captchaText = VerifyCode.GenerateRandomText(4); // 生成随机文本验证码
			byte[] captchaImageBytes = VerifyCode.GenerateCaptchaImage(captchaText); // 生成图片验证码的字节数组
			string base64Image = Convert.ToBase64String(captchaImageBytes); // 将图片字节数组转换为Base64字符串
			string imageSrc = $"data:image/png;base64,{base64Image}"; // 构建图片的src属性值
			var captchaResponse = new {code= 20000, data=new { Text = captchaText, ImageSrc = imageSrc } }; // 创建响应对象
			return Ok(captchaResponse); // 返回JSON响应给前端
		}
	}
}
